using GWB.Application;
using GWB.Application.OnLineShare;
using GWB.Utils.Common;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace GWB.Utils
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration; 
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
           
            services .AddControllersWithViews() 
                    .AddRazorRuntimeCompilation();
            services.AddControllersWithViews();
           

            services.AddScoped<ILogService, LogService>();
            services.AddScoped<IOnLineShareService, OnLineShareService>();
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
           // services.AddHttpContextAccessor();

            services.AddControllers();

            services.Configure<FormOptions>(x =>
            {   x.MultipartBodyLengthLimit = 1024 * 1024 * 1024;
                x.ValueLengthLimit = int.MaxValue;
            });
            services.Configure<KestrelServerOptions>(options =>
            {  options.Limits.MaxRequestBodySize = 1024 * 1024 * 1024;
            });
            services.AddMvc(options =>
            {
                options.Filters.Add(typeof(ActionAttribute));
            });
           
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute (
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute (
                    "areaRoute",
                    "{area:exists}/{controller=Admin}/{action=Index}/{id?}");
            });
        }

    }
}
